package test_junit_shop.Customer;

import org.openqa.selenium.By;
import org.openqa.selenium.support.ui.Select;
import util.BaseDriver;

import java.util.Random;

/**
 * Created by CYH on 2018/2/05.
 * 门店-客户服务-零售客户-车主客户管理-增加删除
 */

public class AddCarOwnerCustomer extends BaseDriver{

    private static AddCarOwnerCustomer instance=new AddCarOwnerCustomer();
    private AddCarOwnerCustomer(){}

    public static AddCarOwnerCustomer getInstance(){
        return instance;
    }


    public void addCarOwnerCustomer() throws InterruptedException {
        Thread.sleep(1000);
        driver=driver.switchTo().frame(2);
        driver.findElement(By.cssSelector("button.btn.btn-sm.btn-outline.btn-primary")).click();
        Thread.sleep(2000);
        driver=driver.switchTo().frame(0);
        driver.findElement(By.id("name")).click();
        driver.findElement(By.id("name")).clear();
        driver.findElement(By.id("name")).sendKeys("策划书");
        driver.findElement(By.id("gender")).click();
        new Select(driver.findElement(By.id("gender"))).selectByVisibleText("保密");
        driver.findElement(By.cssSelector("option[value=\"2\"]")).click();
        driver.findElement(By.id("phone")).click();
        driver.findElement(By.id("phone")).clear();

        String phone="155";
        Random random=new Random();
        int i=8;
        while (i-- >0){
            phone += (random.nextInt(10)+"");
        }


        driver.findElement(By.id("phone")).sendKeys(phone);
        driver.findElement(By.name("address")).click();
        driver.findElement(By.name("address")).clear();
        driver.findElement(By.name("address")).sendKeys("湖南");
        driver.findElement(By.id("vehicles0-vehicleNoFirstStr")).click();
        new Select(driver.findElement(By.id("vehicles0-vehicleNoFirstStr"))).selectByVisibleText("京");
        driver.findElement(By.cssSelector("#vehicles0-vehicleNoFirstStr > option[value=\"1\"]")).click();
        driver.findElement(By.id("vehicles0-vehicleNoSecondStr")).click();
        new Select(driver.findElement(By.id("vehicles0-vehicleNoSecondStr"))).selectByVisibleText("A");
        driver.findElement(By.cssSelector("#vehicles0-vehicleNoSecondStr > option[value=\"1\"]")).click();
        driver.findElement(By.name("vehiclesDetail[0].vehicleNoSuffixStr")).click();
        driver.findElement(By.name("vehiclesDetail[0].vehicleNoSuffixStr")).clear();

        driver.findElement(By.name("vehiclesDetail[0].vehicleNoSuffixStr")).sendKeys(phone.substring(6));
        driver.findElement(By.name("vehiclesDetail[0].vin")).click();
        driver.findElement(By.name("vehiclesDetail[0].vin")).clear();


        driver.findElement(By.name("vehiclesDetail[0].vin")).sendKeys(phone+phone.substring(5));
        driver.findElement(By.id("brand0")).click();
        new Select(driver.findElement(By.id("brand0"))).selectByVisibleText("AC Schnitzer");
        driver.findElement(By.cssSelector("option[value=\"290\"]")).click();
        driver.findElement(By.id("series0")).click();
        new Select(driver.findElement(By.id("series0"))).selectByVisibleText("AC Schnitzer M3");
        driver.findElement(By.cssSelector("option[value=\"2708\"]")).click();
        driver.findElement(By.id("style0")).click();
        new Select(driver.findElement(By.id("style0"))).selectByVisibleText("2015款 ACS3 sport");
        driver.findElement(By.cssSelector("option[value=\"33859\"]")).click();
        driver.findElement(By.id("saleConsultant-id")).click();
        new Select(driver.findElement(By.id("saleConsultant-id"))).selectByVisibleText("iii");
        driver.findElement(By.cssSelector("option[value=\"97\"]")).click();
        driver=driver.switchTo().parentFrame();
        driver.findElement(By.linkText("确定")).click();
    }



}
